package com.py.net.client.input;

import java.util.HashMap;
import java.util.Map;

public class CmdRoute {

	private static Map<String, IInputBuilder> routeMap = new HashMap<>();
	public static void init() {
		for (CmdRouteEnum e : CmdRouteEnum.values()) {
			if (routeMap.containsKey(e.cmd)) {
				throw new RuntimeException("重复注册控制台输入命令");
			}
			routeMap.put(e.cmd, e.inputBuilder);
		}
	}
	
	public static IInputBuilder getInputBuilder(String cmd) {
		return routeMap.get(cmd);
	}
	
	public enum CmdRouteEnum {
		
		Regist("R", new CTSRegistBuilder()),//客户端注册用户
		Chat("S", new CTSChatBuilder()),//客户端给服务端发送聊天协议
		Login("L", new CTSLoginBuilder()),//客户端给服务端发送登陆协议
		ChatLogs("V",new CTSChatLogsBuilder());//客户端给服务端发送查看聊天协议
		
		/** 协议号 */
		public String cmd;
		/** 请求的proto类 */
		public IInputBuilder inputBuilder;
		
		private CmdRouteEnum(String cmd, IInputBuilder inputBuilder) {
			this.cmd = cmd;
			this.inputBuilder = inputBuilder;
		}
	}
	
}
